package com.example.demo.service;

import com.example.demo.entity.Assess;
import com.example.demo.entity.vo.AssessVO;
import com.example.demo.mapper.AssessMapper;
import com.example.demo.mapper.OrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AssessService {

    @Autowired
    private AssessMapper assessMapper;

    @Autowired
    private OrderMapper orderMapper;

    public List<AssessVO> getList(Integer dishId) {
        return assessMapper.getList(dishId);
    }

    public int add(Assess assess, Integer userId) {
        // 判断 assess 关联的 orderId 是否存在
        // 以及该 订单 是否是属于 评论的用户
        if (orderMapper.getList(userId, assess.getOrderId(), null, null).size() != 0) {
            return assessMapper.add(assess);
        }
        return 0;
    }

    public int delete(Integer orderId, Integer dishId) {
        return assessMapper.delete(orderId, dishId);
    }
}
